package com.sjqi.demo.parser;

import com.sjqi.demo.sqlsource.SqlSource;
import com.sjqi.demo.sqlsource.StaticSqlSource;
import com.sjqi.demo.utils.GenericTokenParser;
import com.sjqi.demo.utils.ParameterMappingTokenHandler;

/**
 * @author qishaojun
 * 用来处理#{}之后，获取StaticSqlSource
 */

public class SqlSourceParser {
    public SqlSource parse(String sqlText) {
        ParameterMappingTokenHandler tokenHandler = new ParameterMappingTokenHandler();
        GenericTokenParser tokenParser = new GenericTokenParser("#{", "}", tokenHandler);
        String sql = tokenParser.parse(sqlText);

        return new StaticSqlSource(sql, tokenHandler.getParameterMappings());
    }
}
